<template>
  <div
    class="float-btn"
    :style="btnStyle"
    @click="straight = !straight"
    @mouseenter="mouseHandle(true)"
    @mouseleave="mouseHandle(false)"
  >
    <div class="icon-div">
      <i class="el-icon-s-help"></i>
    </div>

    <!-- 浮动窗口 -->
    <transition :name="transitionName">
      <div v-show="showSlot">
        <slot></slot>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: "XFloatBtn",
  props: {
    btnStyle: {
      type: String,
      default: () => "",
    },
    transitionName: {
      type: String,
      default: () => "el-fade-in",
    },
  },

  watch: {
    straight() {
      this.showSlot = this.showSlot;
    },
  },

  data() {
    return {
      showSlot: false,
      straight: false,
    };
  },
  methods: {
    mouseHandle(boolean) {
      if (this.straight) return;
      this.showSlot = boolean;
    },
  },
};
</script>

<style>
.float-btn {
  position: absolute;
  cursor: pointer;
  z-index: 15;
}

/* 这里建议自己再改改样式 */
.float-btn .icon-div {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  background-color: #ffffff60;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
</style>
